﻿using System;
using System.Collections.Generic;
using System.IO;
using ProjScan.Tools;
using UnityEngine;

namespace ProjScan.Config.GUIConfig
{
	// Token: 0x02000337 RID: 823
	internal class RuleInfoManager : Singleton<RuleInfoManager>
	{
		// Token: 0x0600130F RID: 4879 RVA: 0x00008F63 File Offset: 0x00007163
		public void Init()
		{
			this.dicRuleInfoByPage = new Dictionary<string, Dictionary<string, RuleInfo>>();
			this.dicRuleInfoByID = new Dictionary<string, RuleInfo>();
			this.dicRuleNameToID = new Dictionary<string, string>();
		}

		// Token: 0x06001310 RID: 4880 RVA: 0x0005B548 File Offset: 0x00059748
		public string GetRuleNameById(string ruleId)
		{
			bool flag = this.dicRuleInfoByID == null || this.dicRuleInfoByID.Count == 0;
			if (flag)
			{
				throw new Exception("GetRuleNameById: dicRuleInfoByID is null");
			}
			RuleInfo ruleInfo;
			this.dicRuleInfoByID.TryGetValue(ruleId, out ruleInfo);
			return ruleInfo.ruleName;
		}

		// Token: 0x06001311 RID: 4881 RVA: 0x0005B598 File Offset: 0x00059798
		public string GetRuleIdByName(string ruleName)
		{
			bool flag = this.dicRuleNameToID == null || this.dicRuleNameToID.Count == 0;
			if (flag)
			{
				throw new Exception("GetRuleIdByName: dicRuleNameToID is null");
			}
			string result = null;
			this.dicRuleNameToID.TryGetValue(ruleName, out result);
			return result;
		}

		// Token: 0x06001312 RID: 4882 RVA: 0x0005B5E8 File Offset: 0x000597E8
		public void LoadRuleInfo()
		{
			string path = Path.Combine(ToolsHelper.GetLocationPath(), "RuleInfo.csv");
			Debug.Log(File.ReadAllText(path));
			using (StringReader stringReader = new StringReader(File.ReadAllText(path)))
			{
				string a = stringReader.ReadLine().Replace(" ", "");
				bool flag = a != "PageID,RuleID,RuleName,Description,ExtraInfo,ThresholdCompare,ThresholdDefault,ThresholdDescription,Priority";
				if (flag)
				{
					throw new Exception("RuleInfo file error.");
				}
				Dictionary<string, RuleInfo> dictionary = null;
				string text;
				while ((text = stringReader.ReadLine()) != null)
				{
					char[] separator = new char[]
					{
						','
					};
					string[] array = text.Split(separator);
					string text2 = array[0];
					this.dicRuleInfoByPage.TryGetValue(text2, out dictionary);
					bool flag2 = dictionary == null;
					if (flag2)
					{
						dictionary = new Dictionary<string, RuleInfo>();
						this.dicRuleInfoByPage[text2] = dictionary;
					}
					RuleInfo ruleInfo = default(RuleInfo);
					ruleInfo.pageID = text2;
					ruleInfo.ruleID = array[1];
					ruleInfo.ruleName = array[2];
					ruleInfo.Description = array[3];
					ruleInfo.ExtraInfo = array[4];
					bool flag3 = !string.IsNullOrEmpty(array[5]);
					if (flag3)
					{
						ruleInfo.ThresholdCompare = int.Parse(array[5]);
					}
					bool flag4 = !string.IsNullOrEmpty(array[6]);
					if (flag4)
					{
						char[] separator2 = new char[]
						{
							';'
						};
						string text3 = array[6].Substring(1, array[6].Length - 2);
						ruleInfo.ThresholdDefault = RuleInfoManager.StringToFloat(text3.Split(separator2));
					}
					bool flag5 = !string.IsNullOrEmpty(array[7]);
					if (flag5)
					{
						char[] separator3 = new char[]
						{
							';'
						};
						string text4 = array[7].Substring(1, array[7].Length - 2);
						ruleInfo.ThresholdDescription = text4.Split(separator3);
					}
					bool flag6 = array.Length > 8;
					if (flag6)
					{
						string text5 = array[8];
						string a2 = text5;
						if (!(a2 == "无"))
						{
							if (!(a2 == "自定义"))
							{
								if (!(a2 == "中"))
								{
									if (!(a2 == "高"))
									{
										ruleInfo.RulePriority = RulePriority.None;
									}
									else
									{
										ruleInfo.RulePriority = RulePriority.High;
									}
								}
								else
								{
									ruleInfo.RulePriority = RulePriority.Middle;
								}
							}
							else
							{
								ruleInfo.RulePriority = RulePriority.Custom;
							}
						}
						else
						{
							ruleInfo.RulePriority = RulePriority.None;
						}
					}
					else
					{
						ruleInfo.RulePriority = RulePriority.None;
					}
					dictionary[ruleInfo.ruleID] = ruleInfo;
					this.dicRuleInfoByID.Add(ruleInfo.ruleID, ruleInfo);
					this.dicRuleNameToID.Add(ruleInfo.ruleName, ruleInfo.ruleID);
				}
			}
		}

		// Token: 0x06001313 RID: 4883 RVA: 0x0003A94C File Offset: 0x00038B4C
		public static float[] StringToFloat(string[] string_1)
		{
			bool flag = string_1 == null || string_1.Length == 0;
			float[] result;
			if (flag)
			{
				result = null;
			}
			else
			{
				float[] array = new float[string_1.Length];
				for (int i = 0; i < string_1.Length; i++)
				{
					array[i] = float.Parse(string_1[i]);
				}
				result = array;
			}
			return result;
		}

		// Token: 0x04000B6E RID: 2926
		public Dictionary<string, Dictionary<string, RuleInfo>> dicRuleInfoByPage;

		// Token: 0x04000B6F RID: 2927
		public Dictionary<string, RuleInfo> dicRuleInfoByID;

		// Token: 0x04000B70 RID: 2928
		public Dictionary<string, string> dicRuleNameToID;
	}
}
